/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 31.07.2005
 *
 *************************************************/
package fightplan.business;

import java.io.Serializable;

public enum Result implements Serializable {
	OPEN("Offen"), WON("Gewonnen"), LOST("Verloren"), DISQUALIFIED("Disqualifiziert"), CANCELLED("Aufgabe");

	private static final long serialVersionUID = 1;

	public static final Result[] ALL_VALUES = new Result[] { OPEN, WON, LOST, DISQUALIFIED, CANCELLED };

	private String name;

	Result(String name) {
		this.name = name;
	}

	public static Result parse(String s) {
		for (int i = 0; i < ALL_VALUES.length; i++) {
			if (ALL_VALUES[i].name.equalsIgnoreCase(s)) {
				return ALL_VALUES[i];
			}
		}
		return OPEN;
	}

	// get / set

	public String getName() {
		return name;
	}

	public static boolean isPositive(Result result) {
		return WON.equals(result);
	}

	public static boolean isNegative(Result result) {
		return LOST.equals(result) || DISQUALIFIED.equals(result) || CANCELLED.equals(result);
	}

	public static boolean isOpen(Result result) {
		return result == null || OPEN.equals(result);
	}

	@Override
	public String toString() {
		return getName();
	}

}